﻿var cd = [];
$(function () {
    var s = '';
    var mnum = 1;
    var canup = true;
    $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"></td><td style="font-size:12px;font-weight:bold;">提示：为提供更多即时服务，请长按识别二维码关注公众号</td><td width="70"><a href="javascript:;" onclick="showpic(\'/themes/qrcode.jpg\')" style="background:#FFB700;border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">去关注</a></td></tr></table></td><td style="padding-top:10px;"></td></tr></table>');
    if (d.degree == 1) {
        $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (shop == 1 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：创建店铺并添加商品</td><td width="70"><a href="' + (shop == 1 ? 'javascript:;' : '/my/shopsett') + '" style="background:' + (shop == 1 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (shop == 1 ? '已' : '去') + '完成</a></td></tr></table>');
        mnum++;
        if (shop == 0) {
            canup = false;
        }
    }
    if (d.allnum1 != 0) {
        $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.allnum1 <= d.salenum1 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：完成' + d.allnum1 + '笔系统派单</td><td width="70"><a href="javascript:;" style="background:' + (d.allnum1 <= d.salenum1 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (d.allnum1 <= d.salenum1 ? '已' : '未') + '完成</a></td></tr><tr><td>目前已审核' + d.salenum1 + '个</td></tr></table>');
        mnum++;
        if (d.allnum1 > d.salenum1) {
            canup = false;
        }
    }
    if (d.allnum2 != 0) {
        mnum++;
    }
    for (var i = 0; i < d.buy.length; i++) {
        if (d.buy[i].c) {
            //$('#datas').append('<div>&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：购买' + (d.buy[i].price1 == 0 ? d.buy[i].price2 : d.buy[i].price1) + '元以上商品</td><td width="70"><a href="' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? 'javascript:;' : ('/my/upgrade_shop_dtl?code=' + d.buy[i].shopcode)) + '&x=' + d.buy[i].x + '&price_startorder=' + (d.buy[i].price1 == 0 ? d.buy[i].price2 : d.buy[i].price1) + '" style="background:' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '已' : '去') + '完成</a></td></tr><tr><td style="padding-top:10px;"><table width="100%"><tr><td width="36" style="padding-right:7px;"><img src="' + d.buy[i].shoppic + '" style="width:36px;height:36px;border-radius: 18px;"></td><td><div>' + d.buy[i].shopname + '</div><div style="color:#999;margin-top:5px;">会员：' + d.buy[i].mname + '</div></td></tr></table></td><td style="padding-top:10px;">' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '' : (d.buy[i].sw ? ('<div id="countdown' + mnum + '" style="text-align:center;color:#EF8641;font-size:14px;">&nbsp;</div><div><a href="javascript:;" onclick="switch_shop(' + d.buy[i].x + ')" style="background:none;border-radius: 8px;color:#EF8641;width:70px;height:20px;line-height:20px;display:block;text-align:center;font-size:12px;border:1px solid #EF8641;">更换</a></div>') : (d.buy[i].orderid != 0 && d.buy[i].orderpay == 0 ? ('<div><a href="/shop/prepay?ordercode=' + d.buy[i].ordercode + '" style="background:none;border-radius: 8px;color:#EF8641;width:70px;height:20px;line-height:20px;display:block;text-align:center;font-size:12px;border:1px solid #EF8641;">去支付</a></div>') : ''))) + '</td></tr></table><div>&nbsp;</div>');
            if (d.degree == 0 && d.buy[i].shopcode == '') {
                $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：在系统推荐店铺购买1单' + (d.buy[i].price1 == 0 ? d.buy[i].price2 : d.buy[i].price1) + '元以上商品</td><td width="70"><a href="javascript:;" style="background:' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '已' : '去') + '完成</a></td></tr><tr><td style="padding-top:10px;"><table width="100%"><tr><td width="36" style="padding-right:7px;"></td><td><div style="color:#f00;font-size:14px;text-align:center;">尚无推荐人数据，请重新扫码</div></td></tr></table></td><td style="padding-top:10px;"></td></tr></table>');
                mnum++;
                canup = false;
                continue;
            }
            $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：在系统推荐店铺购买1单' + (d.buy[i].price1 == 0 ? d.buy[i].price2 : d.buy[i].price1) + '元以上商品</td><td width="70"><a href="' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? 'javascript:;' : ('/my/upgrade_shop_dtl?code=' + d.buy[i].shopcode)) + '&x=' + d.buy[i].x + '&price_startorder=' + (d.buy[i].price1 == 0 ? d.buy[i].price2 : d.buy[i].price1) + '" style="background:' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '已' : '去') + '完成</a></td></tr><tr><td style="padding-top:10px;"><table width="100%"><tr><td width="36" style="padding-right:7px;"><img src="' + d.buy[i].shoppic + '" style="width:36px;height:36px;border-radius: 18px;"></td><td><div>' + d.buy[i].shopname + '</div><div style="color:#999;margin-top:5px;">会员：' + d.buy[i].mname + '</div></td></tr></table></td><td style="padding-top:10px;"><div style="text-align:center;"><a href="javascript:;" onclick="showpic(\'' + d.buy[i].mwx + '\')"><img src="/themes/qr.png" style="width:20px;height:20px;"></a></div>' + (d.buy[i].orderid != 0 && d.buy[i].orderpay == 1 ? '' : (d.buy[i].orderid != 0 && d.buy[i].orderpay == 0 ? ('<div><a href="/shop/prepay?ordercode=' + d.buy[i].ordercode + '" style="background:none;border-radius: 8px;color:#EF8641;width:70px;height:20px;line-height:20px;display:block;text-align:center;font-size:12px;border:1px solid #EF8641;">去支付</a></div>') : '')) + '</td></tr></table>');
            //cd.push({ id: mnum, s: d.buy[i].st });
            mnum++;
            if (!(d.buy[i].orderid != 0 && d.buy[i].orderpay == 1)) {
                canup = false;
            }
        }
    }
    //if (cd.length != 0) {
    //    start_countdown();
    //}
    if (d.degree == 1 || d.degree == 2) {
        for (var i = 0; i < 3; i++) {
            if (i + 1 > d.m.length) {
                s += '<td width="33%" style="text-align:center;"><img src="/themes/t2null.png" style="width:36px;height:36px;border-radius: 18px;"></td>';
            }
            else {
                s += '<td width="33%" style="text-align:center;"><img src="' + d.m[i].face + '" style="width:36px;height:36px;border-radius: 18px;"><br>' + d.m[i].name + '</td>';
            }
        }
        $('#datas').append('<div>&nbsp;</div><div style="border-top:1px solid #E2E3E3;">&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.m.length == 3 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：助力3名您推荐的用户成为T' + d.degree + '商家</td><td width="70"><a href="javascript:;" style="background:' + (d.m.length == 3 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;"' + (d.m.length == 3 ? '' : ' onclick="showmyqr()"') + '>' + (d.m.length == 3 ? '已' : '去') + '完成</a></td></tr><tr><td style="padding-top:10px;"><table width="100%"><tr>' + s + '</tr></table></td></tr></table>');
        mnum++;
        if (d.m.length != 3) {
            canup = false;
        }
    }
    //if (d.degree == 2) {
    //    $('#datas').append('<div>&nbsp;</div><table width="100%"><tr><td width="24" style="padding-right:5px;" rowspan="2" valign="top"><img src="/themes/tick' + (d.t2num > 12 ? '1' : '2') + '.png" style="width:100%;padding-top:10px;"></td><td style="font-size:12px;font-weight:bold;">任务' + mnum + '：团队内有12名T1粉丝</td><td width="70"><a href="javascript:;" style="background:' + (d.t2num > 12 ? '#FFDD86' : '#FFB700') + ';border-radius: 8px;color:#fff;width:70px;height:30px;line-height:30px;display:block;text-align:center;font-size:14px;">' + (d.t2num > 12 ? '已' : '未') + '完成</a></td></tr><tr><td>目前已有' + d.t2num + '个</td></tr></table><div>&nbsp;</div>');
    //}
    for (var i = 0; i < h.length; i++) {
        $('#helps').append('<tr><td style="padding: 5px 0px;border-top:1px solid #e3e3e3;"><div style="font-weight:bold;font-size:14px;">' + h[i].title + '</div><div style="color:#888;height:32px;overflow:hidden;" id="h' + i + '" class="jjj">' + h[i].c + '</div></td><td width="80" style="padding: 5px 0px;border-top:1px solid #e3e3e3;"><a href="javascript:;" onclick="showhelp(' + i + ')" style="background:#FFB700;border-radius: 8px;color:#fff;width:70px;height:25px;line-height:25px;display:block;float:right;text-align:center;font-size:12px;">去学习</a></td></tr>');
    }
    if (canup) {
        layer.open({
            title: false
            , content: '<img src="/themes/canup.png" style="width:100%;" onclick="layer.closeAll()">'
            , time: 10
        });
    }
    $('#ddd').css('top', (0 - $('#ss').height()) + 'px');
    showfriends();
});
function showallhelp() {
    $('#hhh').css('display', 'block');
    $('html,body').animate({ scrollTop: $('#hhh').offset().top + 'px' }, 500);
}
function showhelp(n) {
    $('#h' + n).css({
        'height': 'auto',
        'overflow': 'auto'
    });
}
function showfriends() {
    if (f.length == 0) {
        return;
    }
    layer.open({
        title: false
    , content: '<div style="color:#fff;">左右滑动可查看更多<br>或者在"我的">"微信好友"查看<br>长按可保存图片</div><div id="sp" style="width:100%;height:auto;overflow-x:scroll;margin-top:10px;"></div>'
    });
    var s = '';
    for (var i = 0; i < f.length; i++) {
        s += '<td width="' + ($(window).width() * 0.9 - 60) + '"><img src="' + (f[i].m1 == 1 ? f[i].wxpic2 : f[i].wxpic1) + '" style="width:100%;max-width:100%;max-height:100%;"></td>';
    }
    $('#sp').css('width', ($(window).width() * 0.9 - 60) + 'px');
    $('#sp').html('<table width="' + ($(window).width() * 0.9 - 60) * f.length + '"><tr>' + s + '</tr></table>');
}
function showpic(path) {
    layer.open({
        title: false
    , content: '<img src="' + path + '" style="max-width:100%;max-height:400px;" onclick="layer.closeAll()">'
    });
}
function switch_shop(x) {
    //loading();
    //$.post('/dos_m/switch_shop', { x: x }, function (d) { eval(d); });
}
function start_countdown() {
    window.setInterval(countdown, 1000);
}
function countdown() {
    for (var i = 0; i < cd.length; i++) {
        if (cd[i].s >= 3600) {
            $('#countdown' + cd[i].id).html('&nbsp;');
            continue;
        }
        cd[i].s++;
        $('#countdown' + cd[i].id).html(num_add0(((3600 - cd[i].s) - (3600 - cd[i].s) % 60) / 60) + ' : ' + num_add0((3600 - cd[i].s) % 60));
    }
}
function num_add0(n) {
    if (n < 10) {
        return '0' + n.toFixed(0);
    }
    return n.toFixed(0);
}
function ok2() {
    layer.closeAll();
    txttip('正在获取最新数据', function () { location.href = location.href; });
}
function ok() {
    layer.closeAll();
    txttip('操作成功', function () { location.href = location.href; });
}
function err2() {
    layer.closeAll();
    txttip('操作失败', function () { location.href = location.href; });
}
function start_upgrade(_this) {
    //$(_this).prop('disabled', true);
    loading();
    $.post('/dos_m/start_upgrade', {}, function (d) { eval(d); });
}
function err() {
    layer.closeAll();
    txttip('很抱歉，您的权益升级任务尚未全部完成');
}
function showmyqr() {
    if (sc == 0) {
        txttip('您尚未达到T1或未创建店铺，请先去处理');
        return;
    }
    location.href = '/my/sharepic';
}